package com.dao;

import java.util.List;

import com.entity.Brand;
import com.util.Page;
/**
 * 品牌信息
 * @author tiger
 *
 */
public class BrandDao extends BaseDAO {
	
	public boolean saveObject(Brand brand){
		
		return this.saveObject(brand);
	}
	
	/**
	 * 查询所有分类 
	 * @return
	 * @throws Exception
	 */
	public List findCityList() throws Exception{
		return this.queryObject(Brand.class);
	}
	
	/**
	 * 查询单个对象
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Brand editBrand(String id) throws Exception{
		Brand Brand = null;
		Brand = (Brand) this.queryByObjectId(Brand.class, "where :id=?",id);
		return Brand;
	}	
	
	/**
	 * 删除多个商品分类
	 * @param ids
	 * @return
	 */
	public boolean delBrands(String ids){
		String sql = "delete from Brands where id in ("+ids+")";
		return this.executeUpdate(sql);
	}
	/**
	 * 取一级菜单
	 * @return
	 * @throws Exception
	 */
	public List findTopNod() throws Exception{
		String sql  = "select * from Brands where parentid=0";
		return this.findObjectBySql(Brand.class, sql);
	}
	
	/**
	 * 取二级菜单
	 * @return
	 */
	public List findTowNod(){
		String sql = " select * from Brands where parentid  in (select id from Brands where parentid=0)";
		return this.findObjectBySql(Brand.class, sql);
	}
	
	/**
	 * 取二级菜单
	 * @return
	 * @throws Exception 
	 */
	public List findParentBrandById(int id) throws Exception{
		return this.queryObject(Brand.class,"where parentid=?",id);
	}
	
	/**
	 * 取三级菜单
	 * @return
	 */
	public List findThreeNod(){
		String sql = " select * from Brands where parentid  in (select id from Brands where parentid  in (select id from Brands where parentid=0))";
		return this.findObjectBySql(Brand.class, sql);
	}
	
	public boolean delBrand(){
		return false;
	}
	
	public boolean updateBrand(String sql){
		return this.executeUpdate(sql);
	}
	
	public boolean delGtypeById(){
		return false;
	}

	/**
	 * 按分页查询
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public Page findbyPage(Page page) throws Exception{
		return this.queryObjectForPage(Brand.class, page);
	}
}
